package com.example.demo3;

import com.example.demo3.impl.LightSwitchRedImpl;

/**
 * 交通灯类
 * 红灯  黄灯 绿灯 三种状态
 */
public class TrafficLight {

    //初始化为红灯状态
    LightSwitch lightSwitch = new LightSwitchRedImpl();


    public void setLightSwitch(LightSwitch lightSwitch) {
        this.lightSwitch = lightSwitch;
    }

    //切换为绿灯
    public void switchToGreen() {
        lightSwitch.switchToGreen(this);
    }

    //切换为红灯
    public void switchToRed() {
        lightSwitch.switchToRed(this);
    }

    //切换为黄灯
    public void switchToYellow() {
        lightSwitch.switchYellow(this);
    }


}
